﻿using MDT.LifeSewagePlatform.Conmmon;
using MDT.LifeSewagePlatform.Entity;
using MDT.LifeSewagePlatform.InterfaceService;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace MDT.LifeSewagePlatform.ServiceInstance.Controllers
{
    /// <summary>
    /// /
    /// </summary>
    [Route("api/ip")]
    [ApiController]
    [Authorize]
    public class IPAddressController : BaseController
    {
        /// <summary>
        /// /
        /// </summary>
        [Autowired]
        public IIpAddressService ipAddressService { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public IPAddressController()
        {

        }

        /// <summary>
        /// 查询ip
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [CustomActionFilter(Role = RoleType.Admin)]
        public async Task<BaseMessage> GetIps([FromQuery] IpAddressParameter Params)
        {
            return await ipAddressService.GetIpAdressAsync(Params);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="IpDto"></param>
        /// <returns></returns>
        [HttpPost()]
        [CustomActionFilter(Role = RoleType.Admin)]
        public async Task<BaseMessage> Add([FromForm]  IpAddressDto IpDto)
        {
            return await ipAddressService.AddAsync(IpDto);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="IpDto"></param>
        /// <returns></returns>
        [HttpPut("{Id}")]
        [CustomActionFilter(Role = RoleType.Admin)]
        public async Task<BaseMessage> Update(int Id,[FromForm] IpAddressDto IpDto)
        {
            return await ipAddressService.UpdateAsync(Id,IpDto);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpDelete("{Id}")]
        [CustomActionFilter(Role = RoleType.Admin)]
        public async Task<BaseMessage> DeleteIp(int Id)
        {
            return await ipAddressService.DeleteAsync(Id);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpDelete("soft/{Id}")]
        [CustomActionFilter(Role = RoleType.Admin)]
        public async Task<BaseMessage> SoftDeleteIp(int Id)
        {
            int UserId = GetUserID();
            return await ipAddressService.SoftDeleteAsync(Id, UserId);
        }

        //[HttpPut]
        //[AllowAnonymous]
        //public async Task<BaseMessage> Add([FromForm] Model ipAddress)
        //{
        //    //return await ipAddressService.AddAsync(ipAddress);
        //    return null;
        //}
    }
}
